//
//  RCTabBarController.m
//  Example
//
//  Created by Rich on 16/4/20.
//  Copyright © 2016年 Rich. All rights reserved.
//

#import "RCTabBarController.h"
#import "YBHomeVC.h"
#import "YBFoundVC.h"
#import "YBFriendVC.h"
#import "YBMineVC.h"
#import "HorizonLineView.h"

@interface RCTabBarController()

@property(nonatomic,strong) NSArray *titleArray;
@property(nonatomic,strong) NSArray *imageArray;
@property(nonatomic,strong) NSArray *imageHlArray;

@end


@implementation RCTabBarController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self assembleData];
    [self assembleController];
    [self configTabBarItem];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -

- (void)assembleData
{
    self.titleArray = @[@"首页",@"发现",@"朋友",@"我的"];
    self.imageArray = @[@"tab_homePage",@"tab_invest",@"tab_mine",@"tab_mine"];
    self.imageHlArray = @[@"tab_homePageHl",@"tab_investHl",@"tab_mineHl",@"tab_mineHl"];
    
}

- (void)assembleController
{
    YBHomeVC *homeVC = [[YBHomeVC alloc] init];
    YBFoundVC *foundVC = [[YBFoundVC alloc] init];
//    foundVC.areaStatus = 0;
//    foundVC.areaType = 0; //代表所有
    YBFriendVC *friendVC = [[YBFriendVC alloc]init];
    YBMineVC *mineVC = [[YBMineVC alloc]init];
    
    
    UINavigationController *homeNavController = [[UINavigationController alloc] initWithRootViewController:homeVC];
    UINavigationController *projectListNavController = [[UINavigationController alloc] initWithRootViewController:foundVC];
    UINavigationController *friendNavController = [[UINavigationController alloc] initWithRootViewController:friendVC];
    UINavigationController *mineNavController = [[UINavigationController alloc] initWithRootViewController:mineVC];
    self.viewControllers = @[homeNavController,projectListNavController,friendNavController,mineNavController];
    
}


- (void)configTabBarItem
{
    
    for (NSInteger index=0; index<self.viewControllers.count; index++) {
        NSString *title = self.titleArray[index];
        NSString *imageName = self.imageArray[index];
        NSString *imageHlName = self.imageHlArray[index];
        UIImage *image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        UIImage *imageHl = [[UIImage imageNamed:imageHlName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        UINavigationController *navController = self.viewControllers[index];
        UITabBarItem *barItem = [[UITabBarItem alloc] initWithTitle:title image:image selectedImage:imageHl];
        barItem.tag = index;
        navController.tabBarItem = barItem;
    }
    
    [[UITabBarItem appearance]setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:CUSTOM_LIGHT_GRAY,NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:CUSTOM_LIGHT_ORANGE,NSForegroundColorAttributeName,nil] forState:UIControlStateSelected];
    
    CGRect rect = CGRectMake(0.0f, 0.0f, self.tabBar.width, 0.5f);
    HorizonLineView *lineView = [[HorizonLineView alloc] initWithFrame:rect];
    lineView.backgroundColor = LINE_BG_COLOR_2;
    [self.tabBar addSubview:lineView];
    self.tabBar.barTintColor = WHITE_COLOR;
    
    
}



@end